<!DOCTYPE HTML>
<html  lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<link th:href="@{/ajax/libs/summernote/summernote.css}" rel="stylesheet"/>
<link th:href="@{/ajax/libs/summernote/summernote-bs3.css}" rel="stylesheet"/>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content" >
        <form class="form-horizontal m" id="form-comeOn-add" enctype="multipart/form-data">
			<div class="form-group">	
				<label class="col-sm-3 control-label">名称：</label>
				<div class="col-sm-8">
					<input id="name" name="name" class="form-control" type="text">
				</div>
			</div>

			<div class="form-group">
				<label class="col-sm-3 control-label">排序：</label>
				<div class="col-sm-8">
					<input id="sort" name="sort" class="form-control" type="text">
				</div>
			</div>



			<div class="form-group">
				<label class="col-sm-3 control-label">启用状态</label>
				<div class="col-sm-8">
					<div class="input-group" style="width: 100%">
						<select name="status" class="form-control m-b" lay-verify="required">
							<option  value="0">正常</option>
							<option value="1" selected="selected">停用</option>
						</select>
					</div>
				</div>
			</div>


			<div class="form-group">
				<label class="col-sm-3 control-label">添加类型</label>
				<div class="col-sm-8">
					<div class="input-group" style="width: 100%">
						<select name="type" class="form-control m-b" onchange="change(this[selectedIndex].value)"  lay-verify="required">
							<option  value="0">视频</option>
							<option value="1" selected="selected">书籍封面</option>
						</select>
					</div>
				</div>
			</div>

			<div class="form-group" id="eidit">
				<label class="col-sm-3 control-label">公告内容：</label>
				<div class="col-sm-8">
					<input id="noticeContent" name="noticeContent" type="hidden">
					<div class="summernote"></div>
				</div>
			</div>

			<div class="form-group">
				<label class="col-sm-3 control-label">上传</label>
				<div class="col-sm-8">
					<div class="action">
						<div class="new-contentarea tc">
							<a href="javascript:void(0)" class="upload-img"> <label for="avatar">上传</label> </a>
							<input type="file"  name="avatar" id="avatar" />
						</div>
					</div>
				</div>
			</div>

		</form>
		<div class="row">
			<div class="col-sm-offset-5 col-sm-10">
				<button type="button" class="btn btn-sm btn-primary" onclick="submitHandler()"><i class="fa fa-check"></i>保 存</button>&nbsp;
				<button type="button" class="btn btn-sm btn-danger" onclick="closeItem()"><i class="fa fa-reply-all"></i>关 闭 </button>
			</div>
		</div>
	</div>
    <div th:include="include::footer"></div>
	<script th:src="@{/ajax/libs/summernote/summernote.min.js}"></script>
	<script th:src="@{/ajax/libs/summernote/summernote-zh-CN.js}"></script>
    <script type="text/javascript">
		var prefix = ctx + "system/comeOn"
		var showId="xmTanImg";

        $('.summernote').summernote({
            height : '220px',
            lang : 'zh-CN',
            callbacks: {
                onImageUpload: function (files) {
                    sendFile(files[0], this);
                }
            }
        });


        // 上传文件
        function sendFile(file, obj) {
            var data = new FormData();
            data.append("file", file);
            $.ajax({
                type: "POST",
                url: ctx + "common/upload",
                data: data,
                cache: false,
                contentType: false,
                processData: false,
                dataType: 'json',
                success: function(result) {
                    if (result.code == web_status.SUCCESS) {
                        $(obj).summernote('editor.insertImage', result.url, result.fileName);
                    } else {
                        $.modal.alertError(result.msg);
                    }
                },
                error: function(error) {
                    $.modal.alertWarning("图片上传失败。");
                }
            });
        }

        // 当select框属性更改
        function change(value) {
            if(value==0){
                $("#eidit").hide(),
                showId="xmTanVedio";
			}else {
                $("#eidit").show(),
                    showId="xmTanImg";
			}
        }

		$("#form-comeOn-add").validate({
			rules:{
				xxxx:{
					required:true,
				},
			},
			focusCleanup: true
		});
		
		function submitHandler() {
	        if ($.validate.form()) {
	            $.operate.save(prefix + "/add", $('#form-comeOn-add').serialize());
	        }
	    }



        $("#form-answerCover-add").validate({
            rules:{
                xxxx:{
                    required:true,
                },
            },
            focusCleanup: true
        });

        function submitHandler() {
            var sHTML = $('.summernote').summernote('code');
            $("#noticeContent").val(sHTML);
            paht=prefix+"/add"
            $.ajax({
                url:paht,
                type : "POST",
                async: false,
                cache: false,  //此处设置false
                contentType: false,//必须设置false ,formupload1表单中必须设置enctype="multipart/form-data"
                processData: false,  //必须设置fals
                data :new FormData(document.getElementById("form-comeOn-add")),
                success:function (data) {
                    $.operate.successTabCallback(data);
                },
                error:function (XMLHttpRequest, textStatus, errorThrown) {

                }
            })
        }

	</script>
</body>
</html>
